package com.lx.screenshot.ui.translation;

import android.content.Intent;
import android.content.ServiceConnection;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import com.lx.screenshot.databinding.TranslationFragmentBinding;
import com.lx.screenshot.floatWindow.OnScreenResult;
import com.lx.screenshot.floatWindow.ResultWindow;
import com.lx.screenshot.service.floatWindowService.ServiceBinder;
import com.lx.screenshot.util.ScreenShotUtil;


public class TranslationFragment extends Fragment {
    private static final String TAG = "TranslationFragment_Tag";
    private TranslationFragmentBinding binding;
    private ResultWindow resultWindow;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        binding = TranslationFragmentBinding.inflate(inflater, container, false);

//        /* 添加监听事件 */
        addListener();

        ScreenShotUtil.init(getContext().getApplicationContext());

        return binding.getRoot();
    }

    private void addListener() {
        binding.startTransBT.setOnClickListener(v -> {
            new ScreenShotUtil
                    .Builder()
                    .showOnScreenResultLinster(new OnScreenResult() {
                        @Override
                        public void screenSuccess(Bitmap bitmap) {
                            System.out.println(bitmap);
                            // 启动结果悬浮窗
                            resultWindow = new ResultWindow(getContext(), bitmap);
                            resultWindow.create();
                        }
                    });
        });
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

}